package com.health.web.controller.teahouse;

import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.core.page.TableDataInfo;
import com.health.common.enums.BusinessType;
import com.health.common.utils.poi.ExcelUtil;
import com.health.teahouse.domain.Sale;
import com.health.teahouse.domain.ShopSale;
import com.health.teahouse.domain.Vip;
import com.health.teahouse.domain.VipDto;
import com.health.teahouse.service.IVipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员管理Controller
 * 
 * @author yangzw
 * @date 2023-11-30
 */
@RestController
@RequestMapping("/teahouse/vip")
public class VipController extends BaseController
{
    @Autowired
    private IVipService vipService;

    /**
     * 查询会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vip:list')")
    @GetMapping("/list")
    public TableDataInfo list(Vip vip)
    {
        startPage();
        List<VipDto> list = vipService.selectVipList(vip);
        return getDataTable(list);
    }

    /**
     * 导出会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vip:export')")
    @Log(title = "会员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Vip vip)
    {
        List<VipDto> list = vipService.selectVipList(vip);
        ExcelUtil<VipDto> util = new ExcelUtil<VipDto>(VipDto.class);
        util.exportExcel(response, list, "会员管理数据");
    }

    /**
     * 获取会员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vip:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vipService.selectVipById(id));
    }

    /**
     * 查询商品销量统计数据
     */
    //@PreAuthorize("@ss.hasPermi('teahouse:vip:query')")
    @GetMapping("/getGoods")
    public AjaxResult getGoods(@RequestParam String date)
    {
        System.out.println(date);
        List<ShopSale> shopSale = vipService.selectShop(date);
        System.out.println(shopSale);
        // 使用 forEach 迭代 Map
        return success(shopSale);
    }

    /**
     * 查询销售统计数据
     */
    //@PreAuthorize("@ss.hasPermi('teahouse:vip:query')")
    @GetMapping("/getPrices")
    public AjaxResult getPrices(@RequestParam String date)
    {
        System.out.println(date);
        List<Sale> sales = vipService.selectPrices(date);
        System.out.println(sales);
        return success(sales);


    }

    /**
     * 新增会员管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vip:add')")
    @Log(title = "会员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vip vip)
    {
        return toAjax(vipService.insertVip(vip));
    }

    /**
     * 修改会员管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vip:edit')")
    @Log(title = "会员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vip vip)
    {
        return toAjax(vipService.updateVip(vip));
    }

    /**
     * 删除会员管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vip:remove')")
    @Log(title = "会员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vipService.deleteVipByIds(ids));
    }
}
